package com.touch.jgloo;

import java.awt.Color;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import com.touch.jgloo.core.JGLTextObject;
import com.touch.jgloo.owt.JGLComponent;
/**
 * An Object that counts the FPS and draws them to the screen 
 * @author Homicidal Monkey
 * @version 10.1.9
 * @since r461
 * @see com/touch/Licence
 */
public class JGLFPSCounter implements GLEventListener 
{
	private int count = 0;
	private long time = System.currentTimeMillis();
	protected JGLTextObject tFPS;
	public void display(final GLAutoDrawable drawable) 
	{	
		//increase the count value
		count ++;
		//calculate the current fps
		if(System.currentTimeMillis() - time > 1000)
		{
			time = System.currentTimeMillis();		
			tFPS.setCaption("FPS: " + (count));			
			count = 0;
		}
		//draw the fps		
		tFPS.render();
			
	}

	public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
		// TODO Auto-generated method stub
		
	}

	public void init(GLAutoDrawable arg0) 
	{
		//Build the FPS object
		tFPS = JGLTextObject.createTextObject("FPS:    ", JGLComponent.TEXT_TYPE);
		//set the color.
		tFPS.setColor(Color.YELLOW);
	}

	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3,
			int arg4) {
		// TODO Auto-generated method stub
		
	}

}
